package com.then.libary.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileOutputStreamUtils {

	public String saveFile(File file,InputStream stream) throws IOException
	{
		FileOutputStream fileOutputStream = new FileOutputStream(file);
		BufferedInputStream bufferedInputStream = new BufferedInputStream(stream);
		BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
		byte[]  buffer= new byte[1024];
		while(stream.read(buffer)!=-1)
		{
			bufferedOutputStream.write(buffer);
		}
		bufferedOutputStream.flush();
		bufferedOutputStream.close();
		stream.close();
		return file.getAbsolutePath();
	}
}
